#include <string>
#include "Input.h"
#include "Helpers.h"

using std::string;
using std::endl;

//----------------------------------------------------------------------------------
// ParseInputParameters
// Reads the input file and the chain file and initiates the run time input variables.
//
// @param destenationColoringParser
//		the parser for the destination coloring chain file
// @param inputParser
//		the parser for the input variables file.
//
// @throw GraphColoringException
//		in case a parsing error occurred.
//----------------------------------------------------------------------------------
void InputVariables::ParseInputParameters(ChainParser &destenationColoringParser, InputParmetersParser &inputParser)
{

	//parse general parameters
	n = destenationColoringParser.GetBinaryWordLength();
	w = destenationColoringParser.GetBinaryWordWeight();
	numberOfGroupsInDestinationColoring = destenationColoringParser.GetNumberOfGroups();
	
	//copy the destenation chain
	destinationColoring = new int[numberOfGroupsInDestinationColoring];
	int* summery = destenationColoringParser.GetGroupSummary();
	for(int i=0; i<numberOfGroupsInDestinationColoring; i++)
		destinationColoring[i] = summery[i];

	improvedColoringOnly = inputParser.GetImprovedColoringOnly();

	//parse specific parameters
	numberOfIterationsForGreedySearch = inputParser.GetNumberOfIterationsForGreedySearch();
	if (numberOfIterationsForGreedySearch < 0)
		throw(new GraphColoringException( "Could not find parameter: numberOfIterationsForGreedySearch"));
	
	breakingPercentage = inputParser.GetBreakingPercentage();
	if (breakingPercentage < 0)
		throw(new GraphColoringException( "Could not find parameter: breakingPercentage"));

	breakingIterationsGroupSize = inputParser.GetBreakingIterationsGroupSize();
	if (breakingIterationsGroupSize < 0)
		throw(new GraphColoringException( "Could not find parameter: breakingIterationsGroupSize"));
	
	dropPercent = inputParser.GetDropPercent();
	if (dropPercent < 0)
		throw(new GraphColoringException( "Could not find parameter: dropPercent"));

	maxIndexForOptimizations = inputParser.GetMaxIndexForOptimizations();	
	if (maxIndexForOptimizations < 0)
		throw(new GraphColoringException( "Could not find parameter: maxIndexForOptimizations"));
	
	maxIndexForImprovedGreedy = inputParser.GetMaxIndexForImprovedGreedy();
	if (maxIndexForImprovedGreedy < 0)
		throw(new GraphColoringException( "Could not find parameter: maxIndexForImprovedGreedy"));

	percentOfVerticesToStartImprovedGreedy = inputParser.GetPercentOfVerticesToStartImprovedGreedy();
	if (percentOfVerticesToStartImprovedGreedy < 0)
		throw(new GraphColoringException( "Could not find parameter: percentOfVerticesToStartImprovedGreedy"));	

	percentOfVerticesToStopImprovedGreedy = inputParser.GetPercentOfVerticesToStopImprovedGreedy();
	if (percentOfVerticesToStopImprovedGreedy < 0)
		throw(new GraphColoringException( "Could not find parameter: percentOfVerticesToStopImprovedGreedy"));

	numberOfPairsInImprovedGreedy = inputParser.GetNumberOfPairsInImprovedGreedy();
	if (numberOfPairsInImprovedGreedy < 0)
		throw(new GraphColoringException( "Could not find parameter: numberOfPairsInImprovedGreedy"));

	fastMode = inputParser.GetFastMode();
	if (fastMode < 0)
		throw(new GraphColoringException( "Could not find parameter: fastMode"));

	destinationChainSize = inputParser.GetDestinationChainSize();
	if (destinationChainSize < 0)
		throw(new GraphColoringException( "Could not find parameter: destinationChainSize"));

	numberOfIterationsForVertexSearch = inputParser.GetNumberOfIterationsForVertexSearch();
	if (numberOfIterationsForVertexSearch < 0)
		throw(new GraphColoringException( "Could not find parameter: numberOfIterationsForVertexSearch"));

	numberOfIterationsToFillPermutaionChain = inputParser.GetNumberOfIterationsToFillPermutaionChain();
	if (numberOfIterationsToFillPermutaionChain < 0)
		throw(new GraphColoringException( "Could not find parameter: numberOfIterationsToFillPermutaionChain"));

	return;

}
